{itemplate 'public/header'}
<div class="page order-confirm">
	<header class="bar bar-nav">
		<a class="pull-left back" href="javascript:;"><i class="icon icon-arrow-left"></i></a>
		<h1 class="title">提交订单</h1>
	</header>
	<nav class="bar bar-tab no-gutter order-bar">
		<div class="left open-popup open-shop-cart" data-popup=".popup-shop-cart">
			<span class="pull-left">
				已优惠
				<span>￥{$activityed['total']}</span>
			</span>
			<span class="pull-right">
				还需付
				<span class="sum">￥<span class="wait-price">{$waitprice}</span>乘车费</span>
			</span>
		</div>
		<div class="right text-center bg-danger" id="order-submit">确认下单</div>
	</nav>
	<div class="content">
		<form method="post" id="order-form" action="">
			<input type="hidden" name="sid" value="{$sid}">
			<input type="hidden" name="address_id" id="address_id" value="{$address_id}">
			<input type="hidden" name="record_id" id="record_id" value="{$recordid}">
			<input type="hidden" name="note" id="order-note" value="">
			<input type="hidden" name="table_id" id="table_id" value="{$table_id}">
			<div class="content-block-title">店内点餐</div>
			<div class="list-block">
				<ul class="border-1px-tb">
					<li>
						<div class="item-content">
							<div class="item-inner border-1px-b">
								<div class="item-title label">来客人数</div>
								<div class="item-input">
									<input type="text" name="person_num" value="1">
								</div>
							</div>
						</div>
					</li>
					<li>
						<div class="item-content">
							<div class="item-inner border-1px-b">
								<div class="item-title label">下单人</div>
								<div class="item-input">
									<input type="text" name="username" class="{$_W['member']['realname']}" placeholder="您的姓名">
								</div>
							</div>
						</div>
					</li>
				</ul>
			</div>
			<div class="content-block-title">选择支付方式 <span class="color-warning hide">（在线支付立减5元）</span></div>
			<div class="list-block media-list pay-method">
				<ul class="border-1px-tb">
					{loop $store['payment'] $row}
						<li>
							<label class="label-checkbox item-content border-1px-b">
								<div class="item-inner">
									<div class="item-title">{$pay_types[$row]['text']}</div>
								</div>
								<input type="radio" name="pay_type" class="pay_type" value="{$row}" {if $row == 'wechat'}checked{/if}>
								<div class="item-media"><i class="icon icon-form-checkbox"></i></div>
							</label>
						</li>
					{/loop}
				</ul>
			</div>
			<div class="list-block coupon-info">
				<ul class="border-1px-tb">
					<li>
						<a href="javascript:;" class="item-link item-content">
							<div class="item-inner">
								<div class="item-title">代金券</div>
								<div class="item-after color-danger text-right {if !empty($coupons)}open-popup{/if}" data-popup=".popup-coupon">
								{$coupon_text}
								</div>
							</div>
						</a>
					</li>
					{if !empty($conpon)}
						<li class="help-block">
							{if $conpon['use_limit'] == 1}
							<div class="color-danger">本券可与其他优惠叠加使用</div>
							{else}
							<div class="color-gray">本券不可与其他优惠叠加使用</div>
							{/if}
						</li>
					{/if}
				</ul>
			</div>
			<div class="list-block">
				<ul class="border-1px-tb">
					<li>
						<a class="item-link item-content">
							<div class="item-inner border-1px-b">
								<div class="item-title">备注</div>
								<div class="item-after order-note" id="order-note-show">(选填)可填入特殊要求</div>
							</div>
						</a>
					</li>
					{if $store['invoice_status']}
					<li>
						<div class="item-content invoice">
							<div class="item-inner border-1px-b">
								<div class="item-title">需要发票</div>
								<div class="item-after">
									<label class="label-switch invoice-status">
										<input type="checkbox" value="1">
										<div class="checkbox"></div>
									</label>
								</div>
							</div>
						</div>
					</li>
					{/if}
					<li class="hide invoice-value">
						<div class="item-content">
							<input type="text" id="invoice" placeholder="输入个人或者公司抬头"/>
						</div>
					</li>
				</ul>
			</div>
			<div class="list-block detail-info">
				<ul class="border-1px-tb">
					<li>
						<div class="item-content">
							<div class="item-inner border-1px-b">
								<div class="item-title">{$store['title']}</div>
								<div class="item-after"></div>
							</div>
						</div>
					</li>
					<li class="order-list">
						<div class="inner-con border-1px-b">
							{loop $cart['data'] $val}
								{loop $val $val1}
									<div class="row no-gutter">
										<div class="col-60">{$val1['title']}</div>
										<div class="col-20 text-right color-muted">×{$val1['num']}</div>
										<div class="col-20 text-right color-black">￥{$val1['price']}</div>
									</div>
								{/loop}
							{/loop}
						</div>
					</li>
					{if $serve_fee > 0}
						<li class="order-list">
							<div class="inner-con border-1px-b">
								<div class="row no-gutter">
									<div class="col-80">服务费</div>
									<div class="col-20 text-right color-black">￥{$serve_fee}</div>
								</div>
							</div>
						</li>
					{/if}
					{if !empty($activityed['list'])}
						<li class="order-list activity-list">
							<div class="inner-con border-1px-b">
								{loop $activityed['list'] $key $row}
									<div class="row no-gutter">
										<div class="col-50 icon-before"><img src="{WE7_WMALL_TPL_URL}static/img/{$row['icon']}">{$row['name']}</div>
										<div class="col-50 text-right color-black">{$row['text']}</div>
									</div>
								{/loop}
							</div>
						</li>
					{/if}
					<li class="order-list">
						<div class="inner-con border-1px-b">
							<div class="row no-gutter">
								<div class="col-60 color-muted">订单 <span class="color-black">￥{$cart['price']}</span> - 优惠<span class="color-black">￥{$activityed['total']}</span></div>
								<div class="col-20 text-right color-muted">总计</div>
								<div class="col-20 text-right color-black">￥<span class="wait-price">{$waitprice}</span></div>
							</div>
						</div>
					</li>
				</ul>
			</div>
		</form>
	</div>
</div>

<div class="popup popup-remark" id="popup-remark">
	<div class="content-block">
		<div class="popup-header row no-gutter">
			<div class="col-25"><a href=""><span class="icon icon-arrow-left"></span></a></div>
			<div class="col-50 text-center">填写下车地址</div>
			<div class="col-25 text-right"><a href="javascript:;" class="sure close-popup" id="note-submit">确定</a></div>
		</div>
		<div class="popup-body">
			<textarea name="" id="note-textarea" placeholder="请填入下车详细地址"></textarea>
			{if !empty($store['order_note'])}
				<div class="specs-select">
					{loop $store['order_note'] $order_note}
						<span class="spec-item">{$order_note}</span>
					{/loop}
				</div>
			{/if}
		</div>
	</div>
</div>
<div class="popup popup-coupon" id="popup-coupon">
	<div class="page coupon coupon-select">
		<header class="bar bar-nav common-bar-nav">
			<h1 class="title">选择代金券</h1>
		</header>
		<div class="content">
			<div class="content-padded">
				<a href="{php echo imurl('wmall/store/table/post', array('sid' => $sid, 'table_id' => $table_id));}" class="button button-light button-big">不使用代金券</a>
			</div>
			<div class="coupon-list content-padded">
				{loop $coupons $coupon}
				<div class="coupon-list-item" data-recordid="{$coupon['id']}">
					<div class="coupon-panel">
						<label class="label-checkbox item-content">
							<input type="radio" name="recordid" value="{$coupon['id']}" class="coupon-radio">
							<div class="item-media">
								<i class="icon icon-form-checkbox"></i>
							</div>
							<div class="item-inner">
								<div class="row no-gutter">
									<div class="col-40 text-center">
										<div class="price"><span>￥</span>{$coupon['discount']}</div>
										<div class="condition">满{$coupon['condition']}元可用</div>
									</div>
									<div class="col-60">
										<div class="store-title">{$coupon['title']}</div>
										<div class="date">有效期至{php echo date('Y-m-d', $coupon['endtime'])}</div>
									</div>
								</div>
							</div>
						</label>
						<span class="scan-rules">代金券使用规则<span class="icon icon-arrow-down"></span></span>
					</div>
					<ol class="coupon-rules hide">
						<li>
							{if $coupon['use_limit'] == 1}
							可与其他优惠同享
							{else}
							不与其他优惠同享
							{/if}
						</li>
						<li>仅在线支付可用</li>
					</ol>
				</div>
				{/loop}
			</div>
		</div>
	</div>
</div>
<script>
$(function(){
	$(document).on('click', '.scan-rules', function(){
		var $parent = $(this).parents('.coupon-list-item');
		$parent.find('.coupon-rules').toggleClass('hide');
	});

	$(document).on('click', '#popup-coupon .coupon-radio', function(e){
		var recordid = $(this).parents('.coupon-list-item').data('recordid');
		$.closeModal('.popup-coupon');
		$.showIndicator();
		setTimeout(function(){
			location.href = "{php echo imurl('wmall/store/table/post', array('sid' => $sid, 'table_id' => $table_id));}&recordid=" + recordid;
		}, 100);
		return;
	});

	$(document).on('click', '#order-submit', function(){
		var $this = $(this);
		if($(this).hasClass('bg-grey')) {
			return false;
		}
		$(this).removeClass('bg-danger').addClass('bg-grey');
		var person_num = parseInt($(':text[name="person_num"]').val());
		if(isNaN(person_num)) {
			$(this).addClass('bg-danger').removeClass('bg-grey');
			$.toast('来客人数有误');
			return false;
		}
		if(!$('.pay_type:checked').val()) {
			$(this).addClass('bg-danger').removeClass('bg-grey');
			$.toast('请选择支付方式');
			return false;
		}
		var params = {
			record_id: $('#record_id').val(),
			note: $('#order-note').val(),
			pay_type: $('.pay_type:checked').val(),
			invoice: $('#invoice').val(),
			order_type: 3,
			person_num: person_num,
			username: $(':text[name="username"]').val()
		};
		$.post("{php echo imurl('wmall/store/table/submit', array('sid' => $sid, 'table_id' => $table_id));}", params, function(data){
			var result = $.parseJSON(data);
			if(result.message.errno != 0) {
				$(this).addClass('bg-danger').removeClass('bg-grey');
				$.toast(result.message.message);
			} else {
				$.toast('下单成功');
				location.href = "{php echo imurl('system/paycenter/pay', array('sid' => $sid, 'order_type' => 'takeout'));}&id=" + result.message.message;
			}
			return false;
		});
	});

	//备注
	$(document).on('click', '#order-note-show', function(){
		$.popup('.popup-remark');
	});

	$(document).on('click', '#popup-remark .spec-item', function(){
		var note = $('#note-textarea').val();
		$('#note-textarea').val(note + ' ' + $(this).html());
	});

	$(document).on('click', '#note-submit', function(){
		var note = $('#note-textarea').val();
		if(note == '') {
			note = '(选填)可填入特殊要求';
		}
		$('#order-note-show').html(note);
		$('#order-note').val(note);
	});

	//发票
	$(document).on('click', '.invoice-status', function(){
		console.info(($(this).find('input').prop('checked')));
		if($(this).find('input').prop('checked')) {
			$('.invoice-value').removeClass('hide');
		} else {
			$('.invoice-value').addClass('hide');
		}
	});
});
</script>
{itemplate 'public/footer'}